/**
 * 设置iframe的高度,让其自适应
 */
function TuneHeight() {
	var frm = document.getElementById("topFrame");
	var subWeb = document.frames ? document.frames["topFrame"].document : frm.contentDocument;
	if (frm != null && subWeb != null) {
		frm.height = subWeb.body.scrollHeight;
	}
}
String.prototype.Trim = function() {

	return this.replace(/(^\s*)|(\s*$)/g, "");
};

/**
 * 把长度大于len的字符串 截断成 span
 * 
 * @param len
 * @returns {String}
 */
String.prototype.formatStrLength = function(len) {
	var result = this;
	if (result.length > len) {
		result = "<span title='" + this + "'>";
		result += this.substring(0, len) + "...";
		result += "</span>";
	}
	return result;
};

function getlength(strTemp) {

	var i, unLen, bLen;
	var str;
	str = strTemp;// 获得当前域的值

	unLen = str.length;
	bLen = str.length;
	for (i = 0; i < unLen; i++) {
		if (str.charCodeAt(i) > 255)
			bLen++;
	}

	return bLen;

}
/**
 * 是不是数字
 */
function isNumber(text) {
	var newPar = /^\d+$/;
	if (!newPar.test(text)) {
		return false;
	} else {
		return true;
	}
}

function isChineseWord(text) {
	var newPar = /^[\x00-\xff]+$/;
	if (newPar.test(text)) {
		return false;
	} else {
		return true;
	}
}
function isPunctuation(text) {
	var newPar = /^[0-9a-zA-Z\u4E00-\u9FA5]+$/;
	if (!newPar.test(text)) {
		return false;
	} else {
		return true;
	}
}
function isEnglishWord(text) {
	var newPar = /^[a-zA-Z]+$/;
	if (!newPar.test(text)) {
		return false;
	} else {
		return true;
	}
}

/**
 * 校验是否为邮箱
 * @param text
 * @returns {Boolean}
 */
function isEmail(text){
	var newPar = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if (!newPar.test(text)) {
		return false;
	} else {
		return true;
	}
}

function keyDownAction(method, ascCode) {
	if (ascCode == 13) {
		eval(method);
		return false;
	}
	return true;
}
function showWaitDiv(state) {
	if (state) {
		document.body.scroll = "no";
		var width = document.body.clientWidth;
		var height = document.body.clientHeight;
		var myheigth = document.body.clientHeight;
		var showSetupIframe = document.getElementById("waitIframe");
		var showSetupDiv = document.getElementById("apdiv");
		showSetupIframe.style.display = "block";
		showSetupIframe.style.height = myheigth + "px";
		var left = width / 2 - 200;
		var top = height / 2 - 100;
		showSetupDiv.style.left = left + "px";
		showSetupDiv.style.top = top + "px";
		showSetupDiv.style.display = "block"
		if (document.all) {
			showSetupIframe.style.filter = "Alpha(Opacity=75)"; // for IE .
		} else {
			showSetupIframe.style.opacity = 75 / 100; // for FF
		}
	} else {
		document.body.scroll = "yes";
		var showSetupIframe = document.getElementById("waitIframe");
		var showSetupDiv = document.getElementById("apdiv");
		showSetupDiv.style.display = "none"
		showSetupIframe.style.display = "none";
	}
}
//弹出DIV，type:渐现状态，1,0；isClose:是否点击旁边消失，true or false;
function showCustomDiv(state, myDiv, type,isClose) {
	if (state) {
		var width = $(document).width();
		var height = $(document).height();
		var myheigth = $(window).height();
		$("body").append("<div id='boxDiv' />");
		$("body").append("<iframe id='boxFrame' />");
		var showSetupIframe = $("#boxFrame");
		
		var box = $("#boxDiv");
		box.attr("style","top:0; left:0;border:none; position:absolute; z-index:3; display:none;");
		showSetupIframe.attr("style","top:0;background-color:#cccccc;left:0;border:none; position:absolute; z-index:2; display:none;");
		box.animate({
			opacity : 0
		}, 0);
		showSetupIframe.animate({
			opacity : 0.68
		}, 0);
		if(isClose){
			box.click( function(){
				showCustomDiv(0, myDiv, 0,0);
			});
		}
		
		var showSetupDiv = $("#" + myDiv);
		showSetupIframe.show();
		showSetupIframe.height(height);
		showSetupIframe.width(width);
		
		box.show();
		box.height(height);
		box.width(width);
		
		var left = (width - parseInt(showSetupDiv.width())) / 2;
		var top = (myheigth - parseInt(showSetupDiv.height())) / 2 + $(window).scrollTop();
		showSetupDiv.css("top", top);
		showSetupDiv.css("left", left);
		showSetupDiv.show();
	} else {
		var showSetupIframe = $("#boxFrame");
		var box = $("#boxDiv");
		
		var showSetupDiv = $("#" + myDiv);
		if (type == 1) {
			showSetupDiv.hide();
			showSetupIframe.hide();
		} else {
			showSetupDiv.fadeOut("slow");
			showSetupIframe.fadeOut("slow");
		}
		box.unbind("click");
		box.remove();
		showSetupIframe.remove();
	}
}
//偏移量DIV，可以更改坐标
function showRelativeDiv(state, relativeId, divId,offleft,offtop,type) {	
	if(offleft==undefined){
		offleft = 0; 
	}
	if(offtop==undefined){
		offtop = 0;
	}
	var showSetupDiv = $("#" + divId);
	var width = $(document).width();
	var height = $(document).height();
	
	if (state) {
		$("body").append("<div id='passwordIframe' />");
		var myIframe = $("#passwordIframe");
		myIframe.attr("style","top:0; left:0;border:none; position:absolute; z-index:2; display:none;");
		myIframe.animate({
			opacity : 0
		}, 0);
		myIframe.click( function(){
			showRelativeDiv(0, relativeId, divId,offleft,offtop)
		});
		myIframe.show();
		myIframe.height(height);
		myIframe.width(width);
		
		var left = $("#" + relativeId).offset().left;
		var top = $("#" + relativeId).offset().top;
		showSetupDiv.css("top", top+offtop);
		showSetupDiv.css("left", left+offleft);
		showSetupDiv.fadeIn("slow");
	} else {
		var myIframe = $("#passwordIframe");
		myIframe.unbind("click");
		myIframe.remove();
		if(type==1){
			showSetupDiv.fadeOut("slow");
		}else{
			showSetupDiv.hide();
		}
		
	}
}
function encodeText(text) {
	if (text != null && text != "") {
		return encodeURIComponent(text);
	} else {
		return null;
	}
}

function ckDigital(event) {
	// style="ime-mode:disabled" 禁用输入法
	// onparse="return false;"禁用粘贴
	// onkeyup="value=value.replace(/[^\d/.]/g,'')" 只输入数字
	var keycode = event.keyCode || event.charCode; // 火狐的是charCode
	if ((keycode < 48 || keycode > 57)) // 判断是否为数字
		event.preventDefault();
	// event.returnValue=false;
	return false;
}
